package com.administrator.cloudapplication.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;

import com.administrator.cloudapplication.R;
import com.administrator.cloudapplication.activitys.BusQueryActivity;
import com.administrator.cloudapplication.activitys.NavigationActivity;
import com.administrator.cloudapplication.activitys.QueryActivity;
import com.administrator.cloudapplication.adapter.MoreAdapter;
import com.administrator.cloudapplication.base.BaseFragment;
import com.administrator.cloudapplication.models.MoreModel;

import java.util.ArrayList;
import java.util.List;

/**
 * 程序的第四个页面，显示更多内容。
 */

public class MoreFragment extends BaseFragment implements AdapterView.OnItemClickListener {
    View mView;
    GridView gv_more;
    MoreAdapter mMoreAdapter;
    List<MoreModel> moreModelList = new ArrayList<>();
    MoreModel mMoreModel;
    Intent intent;

    @Override
    protected View initView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_more, container, false);
        gv_more = (GridView) mView.findViewById(R.id.gv_more);
        gv_more.setOnItemClickListener(this);
        return mView;
    }

    @Override
    protected void initData() {
        mMoreModel = new MoreModel();
        mMoreModel.setImg(R.mipmap.ic_more_library);
        mMoreModel.setText("图书馆导航");
        moreModelList.add(mMoreModel);
        mMoreModel = new MoreModel();
        mMoreModel.setImg(R.mipmap.ic_more_museum);
        mMoreModel.setText("博物馆导航");
        moreModelList.add(mMoreModel);
        mMoreModel = new MoreModel();
        mMoreModel.setImg(R.mipmap.ic_more_culture);
        mMoreModel.setText("文化政务");
        moreModelList.add(mMoreModel);
        mMoreModel = new MoreModel();
        mMoreModel.setImg(R.mipmap.ic_more_bus);
        mMoreModel.setText("公交查询");
        moreModelList.add(mMoreModel);
        mMoreModel = new MoreModel();
        mMoreModel.setImg(R.mipmap.ic_more_hospital);
        mMoreModel.setText("医院查询");
        moreModelList.add(mMoreModel);
        mMoreModel = new MoreModel();
        mMoreModel.setImg(R.mipmap.ic_more_weather);
        mMoreModel.setText("天气查询");
        moreModelList.add(mMoreModel);
        mMoreModel = new MoreModel();
        mMoreModel.setImg(R.mipmap.ic_more_park);
        mMoreModel.setText("公园查询");
        moreModelList.add(mMoreModel);
        mMoreModel = new MoreModel();
        mMoreModel.setImg(R.mipmap.ic_more_bank);
        mMoreModel.setText("银行查询");
        moreModelList.add(mMoreModel);
        mMoreModel = new MoreModel();
        mMoreModel.setImg(R.mipmap.ic_more_more);
        mMoreModel.setText("更多");
        moreModelList.add(mMoreModel);
        mMoreAdapter = new MoreAdapter(getActivity(), moreModelList);
        gv_more.setAdapter(mMoreAdapter);
    }

    @Override
    protected void initPrepare() {

    }

    @Override
    protected void onInvisible() {

    }


    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
        switch (position) {
            case 0:
            case 1:
            case 2:
                intent = new Intent(getActivity(), NavigationActivity.class);
                intent.putExtra("type", position);
                startActivity(intent);
                break;
            case 3:
                intent = new Intent(getActivity(), BusQueryActivity.class);
                startActivity(intent);
                break;
            case 4:
            case 5:
            case 6:
            case 7:
                intent = new Intent(getActivity(), QueryActivity.class);
                intent.putExtra("type", position);
                startActivity(intent);
                break;
            case 8:
                Toast.makeText(getActivity(), "更多模块正在建设中", Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
